package com.wangwenjun.concurrency.chapter2;

/**
    叫号器Runnable版本
    实现Runnable接口
    这里MAX 和 index 不需要static修饰,因为是一个对象里的
    这里会有线程安全问题
 */
public class TicketWindowRunnable implements Runnable {

    private final int MAX = 50;

    private int index = 1;

    @Override
    public void run() {
        while (index <= MAX){
            System.out.println(Thread.currentThread().getName()+"当前号码:"+index++);
        }
    }

    public static void main(String[] args) {
        TicketWindowRunnable ticketWindowRunnable = new TicketWindowRunnable();
        Thread t1 = new Thread(ticketWindowRunnable,"1号窗口");
        Thread t2 = new Thread(ticketWindowRunnable,"2号窗口");
        Thread t3 = new Thread(ticketWindowRunnable,"3号窗口");
        t1.start();
        t2.start();
        t3.start();
    }

}
